<?php // available_comps.php -- called from local logon scripts from campus computers, increments or decrements the number of available computers in a given lab

require_once("../../tcdb/html/init.php");

// First, let's parse the information in the URL string

/* Eventually, we should have a script that does the following...
   - Looks for $_GET['id'] and $_GET['comp_on']
   - Based on the ID, query the database to see which lab the PC/Mac is in
	- Which I'll have to get manually
   - Pass that as a variable in this script, increments or decrements the available computers based on...
	- comp_on == TRUE // decrement count
	- comp_on == FALSE // increment count

   For now, let's keep it simple for testing purposes */

// GET out variables

if (isset($_GET['id'])) {
    $id = $_GET['id'];
}

if (isset($_GET['comp_on'])) {
    $comp_on = $_GET['comp_on'];
}

// Now, based on the lab, and based on whether $comp_on is true or false, we should increment or decrement the count accordingly

/* Again, a developmental aside -- I envision us pulling the lab that corresponds to the $id from the DB. Then, based on the lab,
   we should pull information from a table in the DB called 'available_computers', which will have rows for labs and the number
   of available computers in the given lab (also a count of the number of PCs vs. Macs). If we can select the appropriate information,
   set it as variables in our script, and increment or decrement accordingly, we should be able to insert the correct information
   back into the DB once we're done, updating the count and making everyone happy again */

// For now, though, just UPDATE the table

// If $comp_on is TRUE, we're marking the computer unavailable
if ($comp_on == 'TRUE')
  {
    $query = "UPDATE available_comps SET comp_on=1
	      WHERE id='$id'";
  }

// Otherwise, we're marking it as available
elseif ($comp_on == 'FALSE')
  {
    $query = "UPDATE available_comps SET comp_on=0
              WHERE id='$id'";
  }

  $run_query = mysql_query ($query);

?>
